package com.guodi.model.controller;


import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.guodi.common.utils.AjaxResult;
import com.guodi.core.boot.ctrl.BaseController;
import com.guodi.core.secure.utils.AuthUtil;
import com.guodi.model.entity.IdtModelLayer;
import com.guodi.model.service.IIdModelLayerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @描述：指标、模型关联图层信息表控制类
 * @作者: 汤厚韬
 * @日期: 2021-1-11
 */
@RestController
@RequestMapping("/IdtModelLayer")
@Api(value = "API - IdtReportFileController", description = "指标、模型关联图层信息表")
public class IdtModelLayerController extends BaseController {

    @Resource
    private IIdModelLayerService iIdModelLayerService;

    /**
     * @描述: 关联图层
     * @入参:
     * @出参:
     * @作者: 汤厚韬
     * @日期: 2021-1-11
     **/
    @PostMapping("/save")
    @ApiOperation(value = "关联图层")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "saveJson", value = "保存JSON", required = true, dataType = "string", paramType = "query")
    })
    public AjaxResult save(String saveJson){
        return iIdModelLayerService.saveIdtModelLayerList(saveJson, AuthUtil.getUser());
    }

    /**
     * @描述: 编辑关联图层
     * @入参:
     * @出参:
     * @作者: 汤厚韬
     * @日期: 2021-1-11
     **/
    @PostMapping("/update")
    @ApiOperation(value = "编辑关联图层")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "主键", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "idtModelId", value = "关联的指标或模型的主键", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "idtModelType", value = "关联的指标或模型类型（0：指标；1：模型）", required = true, dataType = "Integer", paramType = "query"),
            @ApiImplicitParam(name = "layerId", value = "关联图层的主键", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "layerName", value = "关联图层的名称", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "dataType", value = "数据类型（0：目录；1：图层）", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "parentId", value = "上级节点主键", dataType = "string", paramType = "query")
    })
    public AjaxResult update(IdtModelLayer idtModelLayer){
        return iIdModelLayerService.updateIdtModelLayer(idtModelLayer, AuthUtil.getUser());
    }

    /**
     * @描述: 关联图层详情
     * @入参:
     * @出参:
     * @作者: 汤厚韬
     * @日期: 2021-1-11
     **/
    @GetMapping("/detail")
    @ApiOperationSupport(order = 1)
    @ApiImplicitParam(name = "id", value = "主键", dataType = "string", required = true, paramType = "query")
    public AjaxResult detail(String id) {
        return new AjaxResult(iIdModelLayerService.getById(id));
    }

    /**
     * @描述: 获取最多排序数
     * @入参:
     * @出参:
     * @作者: 汤厚韬
     * @日期: 2021-1-11
     **/
    @GetMapping("/selectMaxSort")
    @ApiOperationSupport(order = 1)
    @ApiImplicitParam(name = "parentId", value = "上级节点主键", dataType = "string", required = true, paramType = "query")
    public AjaxResult selectMaxSort(String parentId) {
        return new AjaxResult(iIdModelLayerService.selectMaxSort(parentId));
    }

    /**
     * @描述: 根据主键删除
     * @入参: ids
     * @出参:
     * @作者: 汤厚韬
     * @日期: 2021-1-11
     **/
    @PostMapping("/delete")
    @ApiOperation(value = "根据主键删除")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "ids", value = "ID", required = true,
                    dataType = "string", paramType = "query")
    })
    public AjaxResult delete(String ids) {
        return iIdModelLayerService.deleteIdtModelLayer(ids);
    }

    /**
     * @描述: 新增关联目录
     * @入参:
     * @出参:
     * @作者: 汤厚韬
     * @日期: 2021-1-11
     **/
    @PostMapping("/addRelDir")
    @ApiOperation(value = "新增关联目录")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "parentId", value = "上级节点主键或关联的指标或模型的主键", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "idtModelType", value = "关联的指标或模型类型（0：指标；1：模型）", required = true, dataType = "Integer", paramType = "query"),
            @ApiImplicitParam(name = "layerName", value = "关联图层的名称", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "sort", value = "排序", required = true, dataType = "Integer", paramType = "query")

    })
    public AjaxResult addRelDir(IdtModelLayer idtModelLayer){
        return iIdModelLayerService.addRelDir(idtModelLayer, AuthUtil.getUser());
    }

    /**
     * @描述: 更新关联目录
     * @入参:
     * @出参:
     * @作者: 汤厚韬
     * @日期: 2021-1-11
     **/
    @PostMapping("/updateRelDir")
    @ApiOperation(value = "更新关联目录")
    public AjaxResult updateRelDir(IdtModelLayer idtModelLayer) {
        return iIdModelLayerService.updateRelDir(idtModelLayer, AuthUtil.getUser());
    }

    /**
     * @描述: 根据主键删除关联目录
     * @入参: id
     * @出参:
     * @作者: 汤厚韬
     * @日期: 2021-1-11
     **/
    @PostMapping("/deleteRelDir")
    @ApiOperation(value = "根据主键删除关联目录")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "ID", required = true,
                    dataType = "string", paramType = "query")
    })
    public AjaxResult deleteRelDir(String id) {
        return iIdModelLayerService.deleteRelDir(id);
    }

    /**
     * @描述: 获取指标、模型关联图层列表
     * @入参:
     * @出参:
     * @作者: 汤厚韬
     * @日期: 2021-1-11
     **/
    @PostMapping("/getRelLayerList")
    @ApiOperation(value = "获取指标、模型关联图层列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "parentId", value = "上级节点主键", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "year", value = "选择年份", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "divisionCode", value = "行政区划编号", dataType = "string", paramType = "query")
    })
    public AjaxResult getRelLayerList(String parentId, String year, String divisionCode) {
        return iIdModelLayerService.getRelLayerList(parentId, year, divisionCode);
    }
}
